package cn.edu.scau.cmi.zhengweibo.client.controller;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;

import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.zhengweibo.Factory.BeefMeatFactory;
import cn.edu.scau.cmi.zhengweibo.Factory.PorkMeatFactory;
import cn.edu.scau.cmi.zhengweibo.abstractFactory.domainAbstractClass.ConsumerGetmeat;
import cn.edu.scau.cmi.zhengweibo.abstractFactory.factory.AbstractFactory;
import cn.edu.scau.cmi.zhengweibo.abstractFactory.factory.AonongFactory;
import cn.edu.scau.cmi.zhengweibo.abstractFactory.factory.TianbangFactory;
import cn.edu.scau.cmi.zhengweibo.abstractFactory.factory.WensFactory;
import cn.edu.scau.cmi.zhengweibo.Factory.BeefMeatFactory;
import cn.edu.scau.cmi.zhengweibo.Factory.PorkMeatFactory;
import cn.edu.scau.cmi.zhengweibo.simpleFactoryMethod.MeatFactory;
import cn.edu.scau.cmi.zhengweibo.simpleFactoryMethod.domain.Meat;
import javafx.event.ActionEvent;

import javafx.scene.control.ComboBox;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;

public class AllFactoryViewController implements Initializable{
	@FXML
	private TextArea textarea;
	@FXML
	private ComboBox cb1;
	@FXML
	private ComboBox cb2;
	@FXML
	private ComboBox cb3;
	@FXML
	private Button con1;
	@FXML
	private Button con2;
	@FXML
	private Button con3;
	@FXML
	private ComboBox cb3_3;
	
	public void initialize(URL location, ResourceBundle resources) {
		
		cb1.getItems().addAll("pork","beef","chicken");
		cb1.setPromptText("请选择");
		
		cb2.getItems().addAll("pork","beef");
		cb2.setPromptText("请选择");
		
		cb3.getItems().addAll("Wens","Aonong","Tianbang");
		cb3.setPromptText("请选择品牌");
		
		cb3_3.getItems().addAll("pork","beef","chicken");
		cb3_3.setPromptText("请选择产品");
	}

	
	@FXML
	public void con1(ActionEvent event) {
		MeatFactory meatFactory = new MeatFactory();
		Meat meat;
		meat = meatFactory.getMeat(cb1.getValue().toString());
		textarea.appendText(meat.cook1()+"\n");
	}
	
	@FXML
	public void con2(ActionEvent event) {
		cn.edu.scau.cmi.zhengweibo.Factory.MeatFactory meatFactory = null;
		switch(cb2.getValue().toString()) {
		case "beef": meatFactory=new BeefMeatFactory();break;
		case "pork": meatFactory=new PorkMeatFactory();break;
		default:System.out.println("sorry, your input is not correct");
		}
		if(meatFactory!=null) {
			Meat meat=meatFactory.getMeat();
			textarea.appendText(meat.cook1()+"\n");
		}
	}
	
	@FXML
	public void con3(ActionEvent event) {
		AbstractFactory factory = null ;
		switch(cb3.getValue().toString()){
		case "Wens": factory=new WensFactory();break;
		case "Aonong": factory=new AonongFactory();break;
		case "Tianbang": factory=new TianbangFactory();break;
		default:System.out.println("对不起，输入有误！");
		}
		
		ConsumerGetmeat consumerMeat=null;
		switch(cb3_3.getValue().toString()) {
		case "pork": consumerMeat=factory.createPork();break;
		case "chicken": consumerMeat=factory.createChicken();break;
		case "beef": consumerMeat=factory.createBeef();break;
		default:System.out.println("对不起，输入有误！");
		}
		if(consumerMeat!=null) {
			textarea.appendText(consumerMeat.buy()+"\n");
		}
		
	}
}
